<template>
  <div style="height: 100%">
    <echarts
      :chartStyle="{
        width: '100%',
        height: '100%',
      }"
      :option="option"
      :events="{
        click: handleClick,
      }"
    ></echarts>
  </div>
</template>
<script>
import { Echarts } from "../components";

import * as echarts from "echarts";
import { mountComponent } from "@/utils";
import MapTooltip from "../tooltip/map.vue";

export default {
  components: {
    Echarts,
  },
  data() {
    return {
      option: {},
      chartData: [],
      colorList: [],
    };
  },
  mounted() {
    this.initOption();
  },
  methods: {
    handleClick(params) {
      if (params.seriesType === "effectScatter") {
        this.$emit("click-dot", params);
      }
    },
    initOption() {
      const customIcon =
        "image://";

      echarts.registerMap("yunnan", require("../geojson/yunnan.json"));
      const points = [
        { value: [102.7222, 25.0387], name: "昆明市" },
        { value: [100.2676, 25.6065], name: "大理市" },
        { value: [100.2276, 26.855], name: "丽江市" },
        { value: [103.375, 23.3667], name: "红河哈尼族彝族自治州" },
      ];
      this.option = {
        legend: {
          show: false, // 将图例设置为不显示
        },

        tooltip: {
          show: false,
        },
        geo: {
          map: "yunnan",
          roam: true, // 是否开启放大缩小/拖拽功能
          zoom: 0.8, // 缩放比列
          layoutCenter: ["50%", "40%"], // 地图中心点位置
          layoutSize: "100%",
          label: {
            show: false,
            color: "#fff",
          },

          itemStyle: {
            areaColor: "#296BF0",
            borderColor: "#2ab8ff",
            borderWidth: 0.5,
            shadowColor: "rgba(0,54,255, 0.4)",
            shadowBlur: 100,
          },
          emphasis: {
            //区域激活时的样式
            itemStyle: {
              areaColor: "#2C6DF2",
            },
            label: {
              show: false,
              color: "#fff",
            },
          },
        },
        series: [
          {
            // 带有涟漪特效动画的散点（气泡）图
            type: "effectScatter",
            coordinateSystem: "geo",
            showEffectOn: "render",
            zlevel: 1,
            rippleEffect: false,
            symbol() {
              return customIcon;
            },

            symbolSize: 15, // 标记点大小
            color: "#333",
            fontSize: 18,
            label: {
              show: true,
              color: "white",
              fontSize: 18,
              position: ["-80%", "-200%"],
              formatter: "{b}", // 显示标记点的名称
            },
            data: points,
            tooltip: {
              show: true,
              // trigger: "item",
              backgroundColor: "transparent",
              borderColor: 0,
              textStyle: {
                color: "transparent",
              },
              padding: 0,
              formatter: (params) => {
                // console.log("params", params);
                return mountComponent(MapTooltip, {
                  props: { data: params.data.extra },
                }).$el;
              },
            },
          },
        ],
      };
    },
  },
};
</script>
<style lang="scss" scoped></style>
